﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Xml;
public partial class WebSite_s_image : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int width = 600;  //白色背景宽度
        int height = 300; //高度
        float bili_a = 0, bili_b = 0, bili_c = 0, bili_d = 0;
        bili_a = (float)Session["A"];
        bili_b = (float)Session["B"];
        bili_c = (float)Session["C"];
        bili_d = (float)Session["D"];
       
        DataSet set = new DataSet();
        set = (DataSet)Session["Table"];

        //将结果取出后，则删除Session值
        Session.Remove("A");
        Session.Remove("B");
        Session.Remove("C");
        Session.Remove("D");
        Session.Remove("Table");

        //绘出投票结果
        Bitmap objbitmap = new Bitmap(width, height);//创建一个bitmap实例
        Graphics objgraphics = Graphics.FromImage(objbitmap);
        objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0,width, height);
        System.Drawing.Pen pen = new System.Drawing.Pen(Brushes.Black, 2);//
        objgraphics.DrawString(set.Tables[0].Rows[0][2].ToString()+"的调查结果为:", new Font("宋体", 15), Brushes.Black, new PointF(30, 0));
        objgraphics.DrawString("A:"+(bili_a*100).ToString()+"%",new Font("宋体",15),Brushes.Black,new PointF(30,20));
        objgraphics.DrawRectangle(pen, 100, 20, 300, 20);
        objgraphics.FillRectangle(new SolidBrush(Color.Red), 100, 20, bili_a*300, 20);
        objgraphics.DrawString("B:" + (bili_b * 100).ToString() + "%", new Font("宋体", 15), Brushes.Black, new PointF(30, 50));
        objgraphics.DrawRectangle(pen, 100, 50, 300, 20);
        objgraphics.FillRectangle(new SolidBrush(Color.Red), 100, 50, bili_b*300, 20);
        objgraphics.DrawString("C:" + (bili_c * 100).ToString() + "%", new Font("宋体", 15), Brushes.Black, new PointF(30, 80));
        objgraphics.DrawRectangle(pen, 100, 80, 300, 20);
        objgraphics.FillRectangle(new SolidBrush(Color.Red), 100, 80, bili_c*300, 20);
        objgraphics.DrawString("D:" + (bili_d * 100).ToString() + "%", new Font("宋体", 15), Brushes.Black, new PointF(30, 110));
        objgraphics.DrawRectangle(pen, 100, 110, 300, 20);
        objgraphics.FillRectangle(new SolidBrush(Color.Red), 100, 110, bili_d*300, 20);
        objgraphics.DrawString("A:" + set.Tables[0].Rows[0][3].ToString(), new Font("宋体", 15), Brushes.Black, new PointF(30, 132));
        objgraphics.DrawString("B:" + set.Tables[0].Rows[0][4].ToString(), new Font("宋体", 15), Brushes.Black, new PointF(30, 157));
        objgraphics.DrawString("C:" + set.Tables[0].Rows[0][5].ToString(), new Font("宋体", 15), Brushes.Black, new PointF(30, 182));
        objgraphics.DrawString("D:" + set.Tables[0].Rows[0][6].ToString(), new Font("宋体", 15), Brushes.Black, new PointF(30, 207));
        //将该图片输出到流。
        objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

    }
}
